/*------------------------------------------------------------------------------

 Copyright 2007 Luc Fourestier

 The copyright to the computer program(s) herein is the property of Luc
 Fourestier. The program(s) may be used and/or copied only with the written
 permission of Luc Fourestier or in accordance with the terms and conditions
 stipulated in the agreement/contract under which the program(s) have been
 supplied.

 Contact: luc.fourestier@gmail.com

------------------------------------------------------------------------------*/
/**
 @file    test.c

    This file implements some test.

 @author  Luc Fourestier
 @version 0.1
 @date    2007

*/
/*----------------------------------------------------------------------------*/


/*------------------------------------------------------------------------------
 Includes
------------------------------------------------------------------------------*/

#include "test.h"

#include "ns16550.h"
#include "context.h"

/*------------------------------------------------------------------------------
 Globals
------------------------------------------------------------------------------*/

uint8_t Task1Stack[256];
uint8_t Task2Stack[256];

ContextStruct_t InitStruct  = {NULL, NULL, NULL, NULL};
ContextStruct_t Task1Struct = {Task1Stack + 256, Task1Stack, (void *)test_Task1, NULL};
ContextStruct_t Task2Struct = {Task2Stack + 256, Task2Stack, (void *)test_Task2, NULL};


/*------------------------------------------------------------------------------
 Functions
------------------------------------------------------------------------------*/



/*----------------------------------------------------------------------------*/
/**
 Start the test.

 @param  NONE
 @return Status_t.
*/
/*----------------------------------------------------------------------------*/
Status_t test_Start(void)
{
    Status_t Status = STATUS_OK;

    TRACE_IN(("test_Start"));

    context_Switch((void*) &InitStruct, (void*) &Task1Struct);

    TRACE_OUT((""));
    return(Status);
}


/*----------------------------------------------------------------------------*/
/**
 first task.

 @param  NONE
 @return Status_t.
*/
/*----------------------------------------------------------------------------*/
Status_t test_Task1(void)
{
    Status_t Status = STATUS_OK;
    char Buffer[] = "Task1\r\n";
    unsigned int i = 0;

    TRACE_IN(("test_Task1"));

    while (1)
    {
        ns16550_Write(0, Buffer, 7);

        i = 0;
        while (i<100000)
        {
            i++;
        }

        context_Switch((void*) &Task1Struct, (void*) &Task2Struct);
    }

    TRACE_OUT((""));
    return(Status);
}


/*----------------------------------------------------------------------------*/
/**
 Second task.

 @param  NONE
 @return Status_t.
*/
/*----------------------------------------------------------------------------*/
Status_t test_Task2(void)
{
    Status_t Status = STATUS_OK;
    char Buffer[] = "Task2\r\n\r\n";
    unsigned int i = 0;

    TRACE_IN(("test_Task2"));

    while (1)
    {
        ns16550_Write(0, Buffer, 9);

        i = 0;
        while (i<100000)
        {
            i++;
        }

        context_Switch((void*) &Task2Struct, (void*) &Task1Struct);
    }

    TRACE_OUT((""));
    return(Status);
}




